package com.dm.wallpaper.library.utils;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

public class Log {
    public boolean needSave=false;
    public final static HiLogLabel hiLogLabel = new HiLogLabel(HiLog.INFO, 0x001, "HMOS");

    public static String i(String tag, String info) {
        HiLog.info(hiLogLabel, tag, info);
        Logger.getLogger(tag).info(info);
        return info;
    }

    public static String i(String info) {
        HiLog.info(hiLogLabel, "示例", info);
        Logger.getLogger("示例").info(info);
        return info;
    }

    public static String e(String tag,String info) {
        HiLog.error(hiLogLabel, tag, info);
        Logger.getLogger(tag).warning(info);
        return info;
    }

    public static String e(String info) {
        HiLog.error(hiLogLabel, "错误", info);
        Logger.getLogger("错误").warning(info);
        return info;
    }

    public static String e(String info,Throwable t) {
        HiLog.error(hiLogLabel, "错误", info+"\n错误:"+t.getMessage());
        return info;
    }


    static String Tag = "开始";

    public enum MethodStatus {
        start, complate
    }


    public static void o(String methodName, MethodStatus methodStatus) {
        if (methodStatus == MethodStatus.start) {
            if (Tag.equals("结束")) {
                Tag = "开始";
            }
            Tag += "->" + methodName;
            Log.e("示例", "----------------"+Tag+"          "+Thread.currentThread());
        } else {
            String[] strings = Tag.split("->");
            List<String> tagList = new ArrayList<>();
            for (int i = 0; i < strings.length; i++) {
                tagList.add(strings[i]);
            }

            if (tagList.get(tagList.size() - 1).contains(methodName)) {
                tagList.remove(tagList.size() - 1);
            }
            Tag = "";
            for (int i = 0; i < tagList.size(); i++) {
                if (Tag.equals("")) {
                    Tag = tagList.get(i);
                } else {
                    Tag += "->" + tagList.get(i);
                }
            }

            if (Tag.equals("开始")) {
                Tag = "结束";
            }
            Log.e("示例", "----------------"+Tag + "->" + methodName + "结束"+"          "+Thread.currentThread());
        }

    }
}
